<?php

class FriendsResource extends BaseResource
{
    public function initialize()
    {
        $this->before_filters->skip('specified_user_must_be_authenticated_user',
                                    array('only' => 'get'));
    }
    
    public function get()
    {
        return $this->user->friends->all();
    }
    
    public function post()
    {
        try {
            $friend = User::$objects->get_by_name($this->params['name']);
            $this->user->friends->add($friend);
            if ($this->user->save()) {
                $this->responds_created($friend, 201);
            } else {
                $this->responds_error(400);
            }
        } catch (SRecordNotFound $e) {
            $this->responds_detailed_error('Unknown user !', 400);
        }
    }
}

?>